<template>
  <view class="wrap">
    <view class="box">
      <view class="test">
        <uv-textarea v-model="name" placeholder="请输入短信内容" border='none' height='320rpx' maxlength='20' :customStyle="{backgroundColor: '#F5F5F5'}"></uv-textarea>
      </view>
    </view>
    <view class="desc">*提示：请勿发布与活动无关的内容</view>
    <view class="footer">
      <button class="btn" hover-class="none" :disabled="disabled" @click="signs">{{ btnName }}</button>
      <uv-safe-bottom></uv-safe-bottom>
    </view>
  </view>
</template>

<script setup>
import { ref } from 'vue';
import { useOrder } from '@/store';
import { onLoad } from '@dcloudio/uni-app';
import { post } from '@/api';

const iCloud = useOrder().ICloud;
let id = '';
let target_name = '';
let list = [];
let btnName = ref('发送');
let name = ref('');
let disabled = ref(false);
let phone = uni.getStorageSync('phoneAll');

onLoad((option) => {
  id = option.id;
  target_name = option.name;
  getList();
})

function getList(){
  const params = {
    page: 1,
    limit: 200,
    survey_id: id
  }
  post('api/survey/getSurveyEnrollList', params).then(res => {
    if(res.code == 1){
      const data = res.data;
      list = data.data;
    }
  })
}
function signs(){
  disabled.value = true;
  const dataObj = {
    phoneList: list.map(e => e.mobile),
    name: target_name + name.value,
  }
  iCloud.callFunction({
    name: 'touyanbaoArrSms',
    data: dataObj
  }).then(res => {
    if(res.result.code == 0){
      btnName.value = '已发送';
      setTime();
      preCode = code;
      preTime = new Date().getTime();
    }else{
      btnName.value = '发送';
      disabled.value = false;
      toast(res.result.msg)
    }
  });
}
</script>

<style lang="scss" scoped>
  .footer{
    width: 100%;
    background-color: #fff;
    padding: 0 30rpx;
    padding-top: 16rpx;
    padding-bottom: 30rpx;
    position: fixed;
    left: 0;
    bottom: 0;
  }
  .desc{
    font-weight: 400;
    font-size: 28rpx;
    color: #E43222;
    padding: 0 30rpx;
  }
  .box{
    padding: 30rpx;
    .test{
      background-color: #F5F5F5;
      border-radius: 16rpx;
      overflow: hidden;
    }
  }
</style>